package dd.prog2.exercises.set04;

public class VectorMathTest {

	static int count = 100000; // Durchlaufanzahl beim Zeitmessen
	public static void main(String[] args){
		Vector vDef3 = VectorMathFactory.createVector(4, false);
		Vector vDef = VectorMathFactory.createVector(2, false);
		Vector vOpt = VectorMathFactory.createVector(2, true);

		Matrix mDef = VectorMathFactory.createMatrix(4, 4, false); //new DefaultMatrix(3, 3);
		Matrix mOpt = VectorMathFactory.createMatrix(4, 4, true);//new EfficientMatrix(3, 3);

		vDef3.setall(1);
		vOpt.setall(3);
		vDef.setall(3);
		mDef.setall(4);
		mOpt.setall(4);

		long StartTime, StopTime;
		try{
			StartTime = System.currentTimeMillis();
			for (int i = 0; i < count; i++)
					vOpt.add(vOpt);
			StopTime = System.currentTimeMillis();
			System.out.println("vOpt, Addition: " + (StopTime - StartTime) + " ms");

			StartTime = System.currentTimeMillis();
			for (int i = 0; i < count; i++)
				vDef.add(vDef);
			StopTime = System.currentTimeMillis();
			System.out.println("vDef, Addition: " + (StopTime - StartTime) + " ms\n");

			StartTime = System.currentTimeMillis();
			for (int i = 0; i < count; i++)
				vOpt.mul(vOpt);
			StopTime = System.currentTimeMillis();
			System.out.println("vOpt, SkalarMul: " + (StopTime - StartTime) + " ms");

			StartTime = System.currentTimeMillis();
			for (int i = 0; i < count; i++)
				vDef.mul(vDef);
			StopTime = System.currentTimeMillis();
			System.out.println("vDef, SkalarMul: " + (StopTime - StartTime) + " ms\n");

			StartTime = System.currentTimeMillis();
			for (int i = 0; i < count; i++)
				mOpt.add(mOpt);
			StopTime = System.currentTimeMillis();
			System.out.println("mOpt, Addition: " + (StopTime - StartTime) + " ms");

			StartTime = System.currentTimeMillis();
			for (int i = 0; i < count; i++)
				mDef.add(mDef);
			StopTime = System.currentTimeMillis();
			System.out.println("mDef, Addition: " + (StopTime - StartTime) + " ms\n");

			StartTime = System.currentTimeMillis();
			for (int i = 0; i < count; i++)
				mOpt.mul(vDef3);
			StopTime = System.currentTimeMillis();
			System.out.println("mOpt, SkalarMul: " + (StopTime - StartTime) + " ms");

			StartTime = System.currentTimeMillis();
			for (int i = 0; i < count; i++)
				mDef.mul(vDef3);
			StopTime = System.currentTimeMillis();
			System.out.println("mDef, SkalarMul: " + (StopTime - StartTime) + " ms\n");

			System.out.println("Exception Test !!!");
			mOpt.mul(vDef);
		} catch(ArithmeticException e){
			System.err.println("Check Dimensions !!!");
			e.printStackTrace();
		}
	}

}
